#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int calculate(string s) {
        char sign = '+';
        stack<int> st;
        int num = 0;
        for (int i = 0; i < s.size(); i++) {
            if (isdigit(s[i])) {

                num = num * 10 + s[i] - '0';
            }
            int x = 0;
            if (!isdigit(s[i]) && s[i] != ' ' || i == s.size() - 1) {
                switch (sign) {
                case '+':
                    st.push(num);
                    break;
                case '-':
                    st.push(-(num));
                    break;
                case '*':
                    st.top() *= num;
                    break;
                default:
                    st.top() /= num;

                }
                sign = s[i];
                num = 0;
            }
        }

        int sum = 0;
        while (!st.empty()) {
            sum += st.top();
            st.pop();
        }
        return sum;
    }
};